package com.sghd.fight.module.game.core;

import com.sghd.pojo.fight.game.ChessType;

import java.util.HashMap;
import java.util.Map;

public class Magic {




    /** 魔法上限 */
    public final static int magic_Max = 30;

    /** 魔法值(不包含白色棋子)*/
    private Map<ChessType, Integer> magics = new HashMap<>();

    public Magic(String magicMin) {
        for (ChessType chessType : ChessType.values()) {
            if (chessType == ChessType.CT_LIGHTNING) {
                continue;
            }
            magics.put(chessType,Integer.parseInt(magicMin));
        }
    }

    public Magic() {
    }

    /**
     * 收集
     * @param magics 需要被收集的魔法元素及其值
     */
    public void collect(ChessType chessType) {
        if (chessType != ChessType.CT_LIGHTNING) {
            if (magics.containsKey(chessType)) {
                if (magics.get(chessType) < magic_Max) {
                    magics.put(chessType, magics.get(chessType) + 1);
                }
            } else {
                magics.put(chessType, 30);
            }
        }
    }

    public void clearMagic(){
        magics.clear();
    }

    public void update(ChessType type, int change) {
        int value = (magics.get(type) + change);
        if (value > magic_Max) {
            value = magic_Max;
        }
        if (value < 0) {
            value = 0;
        }
        magics.put(type, value);
    }

    public boolean expend(int[] num, ChessType[] chessTypes) {
        boolean flag = false;
        return flag;
    }

    public Integer getMagic(ChessType type) {
        return magics.get(type);
    }

    public Map<ChessType, Integer> getMagics() {
        return magics;
    }

    public void setMagics(Map<ChessType, Integer> magics) {
        this.magics = magics;
    }
}
